package com.ruoyi.project.notice.category.service;

import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.project.notice.category.domain.Category;
import com.ruoyi.project.notice.category.mapper.CategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl implements ICategoryService
{
    @Autowired
    private CategoryMapper categoryMapper;
    @Override
    public List<Category> selectCategoryList(Category category) {
        return categoryMapper.selectCategoryList(category);
    }

    @Override
    public int insertCategory(Category category) {
        String loginName = ShiroUtils.getLoginName();
        category.setCreateBy(loginName);
        category.setUpdateBy(loginName);
        return categoryMapper.insertCategory(category);
    }

    @Override
    public int deleteById(Long id) {
        return categoryMapper.deleteCategoryById(id);
    }

    @Override
    public int deleteByIds(Long[] ids) {
        int index = categoryMapper.deleteCategoryByIds(ids);
        if(index==ids.length){
            return 1;
        }
        return 0;
    }

    @Override
    public Category selectById(Long id) {
        return categoryMapper.selectById(id);
    }

    @Override
    public int updateCategory(Category category) {
        // 修改时一定要更新修改人及修改时间
        category.setUpdateBy(ShiroUtils.getLoginName());
        return categoryMapper.updateCategory(category);
    }
}
